import json
import logging

from api.BaseService import BaseService


class MemberService(BaseService):
    """
    会员服务
    """

    def __init__(self):
        super().__init__()
        self.service_name = "MemberService"
        logging.info(f"当前远程服务名为{self.service_name}")

    def findByTelephone(self, data):
        """
        :param data:查找用户的手机号
        :return: 返回该手机号用户的信息
        """
        logging.info(f"当前远程服务名为{self.service_name},远程服务方法为findByTelephone")
        logging.info(f"当前测试数据为{data}")
        resp = self.dubbo_client.invoke(self.service_name, "findByTelephone", data)
        logging.info(f"返回值为{json.loads(resp)}")
        return json.loads(resp)

    def add(self, data):
        """
        :param data:添加的用户信息
        :return: 成功返回None,否则返回Failed
        """
        logging.info(f"当前远程服务名为{self.service_name},远程服务方法为add")
        logging.info(f"当前测试数据为{data}")
        resp = self.dubbo_client.invoke(self.service_name, "add", data)
        logging.info(f"返回值为{json.loads(resp)}")
        return json.loads(resp)

    def findMemberCountByMonths(self, data):
        """
        :param data:查询日期
        :return: 返回该日期内添加的会员人数
        """
        logging.info(f"当前远程服务名为{self.service_name},远程服务方法为findMemberCountByMonths")
        logging.info(f"当前测试数据为{data}")
        resp = self.dubbo_client.invoke(self.service_name, "findMemberCountByMonths", data)
        logging.info(f"返回值为{json.loads(resp)}")
        return json.loads(resp)


# if __name__ == '__main__':
    # ms = MemberService()
    # print(ms.findByTelephone("10007897419"))
    # info = {"id": 325, "name": "战斗暴龙兽", "phoneNumber": "10007897419", "class": "com.itheima.pojo.Member"}
    # print(ms.add(info))
    # data = ["2022-11", "2022-12"]
    # print(ms.findMemberCountByMonths(data))
